package com.demo.htmlunitDemo;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

/**
 * Hello world!
 *
 */
public class App {
	public static void main(String[] args) throws Exception {
		WebClient webClient = new WebClient(BrowserVersion.CHROME);
		webClient.getOptions().setCssEnabled(false);
		webClient.getOptions().setJavaScriptEnabled(true);
		webClient.getJavaScriptEngine();
		webClient.setJavaScriptTimeout(5000);
		webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
		webClient.getOptions().setThrowExceptionOnScriptError(false);
		HtmlPage page = webClient
				.getPage("https://my.oschina.net/apdplat/blog/217586?p=1");
		Document document = Jsoup.parseBodyFragment(page.asXml());
		System.out.println(document.getElementsByTag("body").iterator().next()
				.html());
		webClient.closeAllWindows();
	}
}
